#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int N = 1007;
priority_queue<ll,vector<ll>,less<> >q[N];
ll a[N],s[N];
int main()
{
	int n,m;
	cin>>n>>m;
	for(int i=1;i<=m;i++)cin>>a[i];
	ll ans=0;
	for(int j=1;j<=n;j++)
	{
		s[j]+=j;
		string ss;
		cin>>ss;
		for(int i=1;i<=ss.size();i++)
		{
			if(ss[i-1]=='o')s[j]+=a[i];
			else q[j].push(a[i]);
		}
		if(ans==s[j])ans++;
		else ans=max(ans,s[j]);
	}
//	for(int i=1;i<=n;i++)cout<<s[i]<<" ";
	for(int i=1;i<=n;i++)
	{
		int cnt=0;
		while(s[i]<ans&&q[i].size())
		{
			ll t=q[i].top();
			q[i].pop();
			s[i]+=t;
			cnt++;
		}
		cout<<cnt<<endl;
	}
	return 0;
}
